home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 008 / egapas.arc / EGA.PAS
Encoding:
Pascal/Delphi Source File  |  1984-12-18  |  4.6 KB  |  189 lines

  1. {
  2. Organization: UWisconsin-Madison Academic Comp Center
  3. Lines: 181
  4.  
  5. This is a little demo program that takes advantage of the
  6. 640X350 by 16 color graphics capabilities of the IBM Enhanced Graphics
  7. Adapter when used with the Enhanced Color Monitor.  As yet, TURBO
  8. doesn't support this particular mode, so I've used interrupt 10H for
  9. all the plotting.  The graphics primitives that are used are
  10. plot_point, and plot_line (draw a line).
  11.  
  12.  
  13. -Alan Curtis
  14. }
  15. {----------------cut here---------------}
  16. program interrupt(input,output);
  17. {this program uses the high resolution mode, 640X350 by 16 color graphics
  18.  that are available with the enhanced graphics adapter and enhanced color
  19.  monitor.  This was written by Alan Curtis, 1985.                        }
  20.  
  21. var
  22.   j,k,page : integer;
  23.  
  24. {////////////////////////////}
  25.  
  26. procedure super_hires;
  27. {set resolution to 640X350 by 16 color mode}
  28. type
  29.   result = record
  30.     al,ah,bl,bh : byte;
  31.     cx,dx,bp,si,di,ds,es,flags : integer;
  32.   end;
  33. var
  34.   int_result : result;
  35.   col : byte;
  36. begin
  37.   with int_result do begin
  38.     al := $10;  {graphics mode}
  39.     ah := $0;
  40.   end;
  41.   intr($10,int_result);  {high res mode}
  42. end;
  43.  
  44. {////////////////////////////}
  45.  
  46. procedure set_page(page : integer);
  47. {sets active display page - must have 128K of graphics memory}
  48. type
  49.   result = record
  50.     al,ah,bl,bh : byte;
  51.     cx,dx,bp,si,di,ds,es,flags : integer;
  52.   end;
  53. var
  54.   int_result : result;
  55.   b_page : byte;
  56. begin
  57.   b_page := page;
  58.   int_result.ah := $5;
  59.   int_result.al := b_page;  {active page}
  60.   intr($10,int_result);
  61. end;
  62.  
  63. {////////////////////////////}
  64.  
  65. procedure plot_point(row,col,color,page : integer);
  66. {plots a point at row,col in the specified color (0-15), at the
  67.  specific page}
  68. type
  69.   result = record
  70.     al,ah,bl,bh : byte;
  71.     cx,dx,bp,si,di,ds,es,flags : integer;
  72.   end;
  73. var
  74.   int_result : result;
  75.   b_page,b_color : byte;
  76.  
  77. begin
  78.   b_page := page;
  79.   b_color := color;
  80.   int_result.ah := $C;
  81.   int_result.bh := b_page;  {active page}
  82.   int_result.al := b_color;
  83.   int_result.dx := row;
  84.   int_result.cx := col;
  85.   intr($10,int_result);
  86. end;
  87.  
  88. {////////////////////////////}
  89.  
  90. procedure plot_line(x1,y1,x2,y2 : real; color,page : integer);
  91. {draws a line from x1,y1 to x2,y2 in the specified color}
  92. type
  93.   result = record
  94.     al,ah,bl,bh : byte;
  95.     cx,dx,bp,si,di,ds,es,flags : integer;
  96.   end;
  97. var
  98.   counter : real;
  99.   int_result : result;
  100.   dx,dy,ddx,ddy,newx,newy : real;
  101.   b_page,b_color : byte;
  102.   xmult,ymult : integer;
  103.  
  104. begin
  105.   b_page := page;
  106.   b_color := color;
  107.   int_result.ah := $C;
  108.   int_result.bh := b_page;  {active page}
  109.   int_result.al := b_color;
  110.   int_result.dx := round(y1);
  111.   int_result.cx := round(x1);
  112.   intr($10,int_result);
  113.  
  114.   dx := x2 - x1;
  115.   if dx < 0.0 then xmult := -1 else xmult := 1; {increment can be negative}
  116.   dy := y2 - y1;
  117.   if dy < 0.0 then ymult := -1 else ymult := 1;
  118.  
  119.   {before getting ratios, check for zeros in dx and dy}
  120.   if dy = 0.0 then begin
  121.     {x will be incremented by 1 through every loop, y by 0}
  122.     ddx := 1.0 * xmult;
  123.     ymult := 0;
  124.     dy := abs(dx);    {fool loop counter below}
  125.   end
  126.   else if dx = 0.0 then begin
  127.     ddx := 2;
  128.     ddy := 1 * ymult;
  129.     xmult := 0;
  130.     dx := abs(dy);    {fool loop counter}
  131.   end
  132.   else begin
  133.     ddx := abs(dx/dy);  {get ratio}
  134.     ddy := abs(dy/dx);
  135.     ddx := ddx*xmult;
  136.     ddy := ddy*ymult;
  137.   end;
  138.  
  139.   {the following initializations are used in the proceeding loops}
  140.   newy := y1;
  141.   newx := x1;
  142.   counter := 0.0;
  143.   dy := abs(dy);
  144.   dx := abs(dx);
  145.  
  146.   if abs(ddx) <= 1.0 then
  147.   while counter < dy do begin
  148.     counter := counter + 1.0;
  149.     newx := newx + ddx;
  150.     newy := newy + ymult;
  151.     int_result.ah := $C;
  152.     int_result.bh := b_page;  {active page}
  153.     int_result.al := b_color;
  154.     int_result.dx := round(newy);
  155.     int_result.cx := round(newx);
  156.     intr($10,int_result);
  157.   end
  158.  
  159.   else while counter < dx do begin  {x will be incremented by 1}
  160.     counter := counter + 1.0;
  161.     newx := newx + xmult;
  162.     newy := newy + ddy;
  163.     int_result.ah := $C;
  164.     int_result.bh := b_page;  {active page}
  165.     int_result.al := b_color;
  166.     int_result.dx := round(newy);
  167.     int_result.cx := round(newx);
  168.     intr($10,int_result);
  169.   end;
  170. end;
  171.  
  172. {****************************}
  173. {begin main}
  174. begin
  175.   super_hires;
  176.   page := 0;
  177.   set_page(page);
  178.   plot_line(0.0,0.0,639.0,0.0,9,0);
  179.   plot_line(639.0,0.0,639.0,349.0,9,0);
  180.   plot_line(639.0,349.0,0.0,349.0,9,0);
  181.   plot_line(0.0,349.0,0.0,0.0,9,0);
  182.   for j := 1 to 15 do
  183.    for k := 1 to 10 do
  184.      plot_line(j*10.0+k,1.0,349.0+j*10.0+k,350.0,j,0);
  185. end.
  186.  
  187.  
  188. %
  189.